﻿using Donal.Xms.API.OAuth;
using Donal.Xms.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Donal.Xms.Web.api.oauth.weixin
{
    public partial class barCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //获得配置信息
            oauth_config config = oauth_helper.get_config(4);
            if (config == null)
            {
                Response.Write("出错了，您尚未配置微信的API信息！");
                return;
            }

            string turl = Utils.GetCookie(DTKeys.COOKIE_URL_REFERRER);
            if (string.IsNullOrEmpty(turl) || turl == HttpContext.Current.Request.Url.ToString().ToLower())
            {
                turl = new Donal.Xms.Web.UI.BasePage().linkurl(0,"usercenter");
            }
            hidUrl.Value = turl;
            hidCode.Value = DESEncrypt.Encrypt(DateTime.Now.ToString("yMdHmsms") + Utils.Number(3));
           
            string state = Guid.NewGuid().ToString().Replace("-", "");
            Session["oauth_state"] = state;
            string send_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + config.oauth_app_id
                + "&redirect_uri=" + Utils.UrlEncode(config.wx_return_uri + "?duid=" + hidCode.Value)
                + "&response_type=code&scope=snsapi_userinfo&state=" + state + "#wechat_redirect";

            Utils.WriteCookie("imglink", send_url);
            this.barCodes.ImageUrl = "/tools/QRCode.ashx";
        }
    }
}